/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/12/02
*/
#include "LuaButton.h"
#include "../../utilities/Log.h"

#ifdef EDUI_USE_LUAPLUS

EDUI_NAMESPACE_BEGIN

#define CObjPtr (Button::ToButton(m_cobj))

void* LuaButton::GetInterface(void* data)
{
    if (!data) return 0;
    LuaButton* button = new LuaButton((Button*)data);
#ifdef EDUI_TEST_NEW_DELETE
    ++m_newdeleteNum;
    Log("[LuaButton] new LuaButton : %d, %d", button, data);
#endif
    return button;
}

void LuaButton::Release()
{
#ifdef EDUI_TEST_NEW_DELETE
    --m_newdeleteNum;
    Log("[LuaButton] delete LuaButton : %d, %d, %s", this, m_cobj, this->GetName());
#endif
    delete this;
}

LuaButton::LuaButton(Button* button) : LuaLabel(button)
{}

LuaButton::~LuaButton()
{}

//----------------------------------------//

void LuaButton::SetPressedOffset(int x, int y)
{
    CObjPtr->SetPressedOffset(x, y);
}

int LuaButton::GetPressedOffset(LuaState *L)
{
    Point pt = CObjPtr->GetPressedOffset();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &pt);
    obj.Push(L);
    return 1;
}

//----------------------------------------//

void LuaButton::Register(LuaState *L)
{
    LuaObject obj = LuaHelperNS::AddToMetas(L, "Button", "Label");
    obj.SetObject("__index", obj);
    obj.RegisterDirect("__NewCObj__", &LuaButton::GetInterface);

    obj.RegisterObjectDirect("SetPressedOffset", (LuaButton*)0, &LuaButton::SetPressedOffset);
    obj.RegisterObjectFunctor("GetPressedOffset", &LuaButton::GetPressedOffset);
}

#undef CObjPtr

EDUI_NAMESPACE_END

#endif